package first;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class Sender {
	
	private static final int SEND_NUMBER = 5;

	public static void main(String[] args) throws JMSException {
		
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
//				ActiveMQConnection.DEFAULT_USER,
//				ActiveMQConnection.DEFAULT_PASSWORD,
//				"tcp://localhost:61616"
				);
		Connection connection = connectionFactory.createConnection();
		connection.start();
		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
		
		Destination destination = session.createQueue("FirstQueue");
		MessageProducer producer = session.createProducer(destination);
		producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
		
		
		for(int i = 0; i < SEND_NUMBER; i++){
			
			String text = "Active MQ 发送的消息:" + i;
			System.out.println(text);
			TextMessage message = session.createTextMessage(text);
			producer.send(message);
		}
		
		session.commit();
		connection.close();
	}
}
